<template>
  <div class="u-p-20 user">
    <el-card shadow="never" class="user-info">
      <div slot="header">
        <span>
          <b class="u-f-16">用户信息</b>
        </span>
        <div class="u-right u-5mt">
          <el-button size="small" icon="el-icon-back" @click="$router.go(-1)">返回</el-button>
        </div>
      </div>

      <div class="hd">
        <el-image :src="objForm.head_img" fit="cover" lazy class="avatar"></el-image>
        <div class="nickname">{{objForm.nick_name}}</div>
      </div>
      <div class="u-mt-20">
        <el-form label-width="80px">
          <el-form-item label="手机号">{{objForm.phone}}</el-form-item>
          <el-form-item label="性别">
            <el-tag v-if="objForm.sex===1">男</el-tag>
            <el-tag v-else-if="objForm.sex===2">女</el-tag>
            <el-tag v-else>保密</el-tag>
          </el-form-item>
          <el-form-item label="账号状态">
            <el-tag type="warning" v-if="objForm.status===1">正常</el-tag>
            <el-tag type="success" v-else>停用</el-tag>
          </el-form-item>
          <el-form-item label="收益">{{objForm.earnings_price}}</el-form-item>
          <el-form-item label="余额">
            {{objForm.pay_price}}
            <el-button type="primary" class="pay-btn" size="small" @click="addUserPrice">充值/扣除</el-button>
          </el-form-item>
          <el-form-item label="openid">{{objForm.wx_open_id}}</el-form-item>
          <el-form-item label="注册时间">{{objForm.create_time}}</el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card shadow="never" class="user-panel">
      <el-tabs v-model="activeTab">
        <el-tab-pane label="用户地址" name="address">
          <user-address :user-id="objForm.id+''" v-if="activeTab==='address'"></user-address>
        </el-tab-pane>

        <el-tab-pane label="用户收益" name="earnings">
          <user-earnings :user-id="objForm.id+''" v-if="activeTab==='earnings'"></user-earnings>
        </el-tab-pane>
        <el-tab-pane label="用户推广列表" name="poplist">
          <user-poplist :user-id="objForm.id+''" v-if="activeTab==='poplist'"></user-poplist>
        </el-tab-pane>
        <el-tab-pane label="用户余额日志" name="balance">
          <user-balance :user-id="objForm.id+''" v-if="activeTab==='balance'"></user-balance>
        </el-tab-pane>
      </el-tabs>
    </el-card>

    <!-- 修改余额弹窗 -->
    <el-dialog title="用户余额修改" :visible.sync="is_price_show" width="30%">
      <el-form :model="objForm" label-width="80px">
        <el-form-item label="变动类型">
          <el-radio v-model="type" label="add">增加</el-radio>
          <el-radio v-model="type" label="deduct">扣除</el-radio>
        </el-form-item>
        <el-form-item label="变动金额">
          <el-input v-model="pay_price" type="text" placeholder="请输入变动金额"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogClosePrice">关 闭</el-button>
        <el-button type="primary" @click="submitPrice()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import commonEdit from "@/mixins/common-edit";
import userAddress from "@/views/user/address";
import userEarnings from "@/views/user/earnings";
import userPoplist from "@/views/user/poplist";
import userBalance from "@/views/user/balance";
export default {
  mixins: [commonEdit],
  components: {
    userAddress,
    userEarnings,
    userPoplist,
    userBalance
  },
  data() {
    return {
      activeTab: "address",
      apiName: "user",
      objForm: {}, //用户信息
      is_price_show: false,
      pay_price: 0,
      type: "add"
    };
  },
  methods: {
    dialogClosePrice() {
      this.is_price_show = false;
    },
    addUserPrice() {
      this.is_price_show = true;
    },
    submitPrice() {
      var id = this.objForm.id;
      var pay_price = this.pay_price;
      var type = this.type;
      let self = this;
      var data_josn = {id:id,pay_price:pay_price,type:type};
      self.$api[self.apiName].userChangePrice(data_josn).then(response => {
        if (response.code == 1) {
         self.getInfo();
        }
      });
      this.is_price_show = false;
    }
  },
  created() {}
};
</script>

<style lang="scss" scoped >
.pay-btn {
  margin-left: 50px;
}
.el-form-item__content {
  line-height: 40px;
}
.el-form-item .el-form-item__content {
  line-height: 40px;
}

.user {
  display: flex;

  .user-info {
    width: 400px;

    .hd {
      text-align: center;

      .avatar {
        width: 80px;
        height: 80px;
        border-radius: 50%;
        box-shadow: 0 3px 10px #dcdcdc;
      }
      .nickname {
        font-size: 16px;
        margin-top: 10px;
      }
    }
  }
  .user-panel {
    flex: 1;
    margin-left: 20px;
  }
}
</style>
